/**
 *
 */
package com.china.lee.getpi;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * The Class getPiFromCalc.
 * 
 * @author li-l
 */
public class getPiFromCalc {

	/**
	 * The main method.
	 * 
	 * @param args the arguments
	 */
	public static void main(String[] args) {
		BigDecimal pi_bg = new BigDecimal(0.0);
		double sign = 1;
		long n = 100;
		System.out.println("please input number:");
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			n = Long.valueOf(reader.readLine());
		} catch (IOException ex) {
		} catch (Exception ex) {
		}
		int scale = 100;
		System.out.println("please input scale(number):");
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			scale = Integer.valueOf(reader.readLine());
		} catch (IOException ex) {
		} catch (Exception ex) {
		}
		BigDecimal one = new BigDecimal(1.0);
		for (int i = 1; i < n; i += 2) {
			BigDecimal i_bg = new BigDecimal(i * 1.0);

			pi_bg = pi_bg.add(one.divide(i_bg, scale, RoundingMode.UP).multiply(new BigDecimal(sign)));
			sign *= -1;
		}
		pi_bg = pi_bg.multiply(new BigDecimal(4.0));
		System.out.println("Pi is:"
				+ pi_bg.toString());
		System.out.println("SYS Pi is:"
				+ Math.PI);
	}

}
